package com.jk.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jk.controller.BaseController;
import com.jk.pojo.Executives;
import com.jk.pojo.Project;
import com.jk.pojo.Recruit;
import com.jk.service.ProjectService;
import com.jk.service.RecruitDeliveryService;
import com.jk.service.ExecutivesService;

/**
 *
 * @author jdz
 *
 */
@Controller
@RequestMapping("/admin/executives/")
public class ExecutivesController extends BaseController {
private static final String JSP_PATH = "/executives/";

	@Resource
	private ExecutivesService executivesService;

	@Resource
	private RecruitDeliveryService recruitDeliverService;

	@Resource
	private ProjectService projectService;

	/**职位信息管理列表
	 * @param request
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("list.do")
	public String query(HttpServletRequest request,ModelMap modelMap) {
		try {
			List<Executives> varList = executivesService.queryAll();
			if(modelMap != null){
				modelMap.addAttribute("varList",varList);
	        }

		} catch (Exception e) {
			e.printStackTrace();
		}
		return JSP_PATH+"executives-list";
	}

	/**高管详情
	 * @param request
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("view/{id}.do")
	public String view(HttpServletRequest request,ModelMap modelMap, @PathVariable("id") Long id) {
		try {
			//Executives executives = executivesService.queryById(id);
			//modelMap.clear();
			Executives executives = executivesService.queryCompleteInfoById(id);
			//modelMap.addAttribute("executives",executives);
			modelMap.put("executives", executives);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return JSP_PATH+"executives-view";
	}

	/**
	 * @param request
	 * @param modelMap
	 * @return
	 */
	@ResponseBody
	@RequestMapping("add.do")
	public Map addNewExecutives(HttpServletRequest request,ModelMap modelMap) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			//自荐人姓名
			String name = String.valueOf(request.getParameter("name"));
			//身份证号
			String idCard = String.valueOf(request.getParameter("idCard"));
			//手机号码
			String mobilephone = String.valueOf(request.getParameter("mobilephone"));
			//QQ
			String qq = String.valueOf(request.getParameter("qq"));
			//电子邮箱地址
			String email = String.valueOf(request.getParameter("email"));
			//户籍所在地址
			int residence = Integer.parseInt(String.valueOf(request.getParameter("residence")));
			//通讯地址
			int address = Integer.parseInt(String.valueOf(request.getParameter("address")));
			//自荐理由
			String reason = String.valueOf(request.getParameter("reason"));
			//创业看法
			String opinion = String.valueOf(request.getParameter("opinion"));
			//关注行业
			int desiredIndustry = Integer.parseInt(String.valueOf(request.getParameter("desiredIndustry")));
			//最终学历
			int education = Integer.parseInt(String.valueOf(request.getParameter("education")));
			//毕业学校
			String graduateSchool = String.valueOf(request.getParameter("graduateSchool"));
			//专业
			String subject = String.valueOf(request.getParameter("subject"));
			//教育模式
			int educationScheme = Integer.parseInt(String.valueOf(request.getParameter("educationScheme")));
			//海外教育经验
			int overseaEducation = Integer.parseInt(String.valueOf(request.getParameter("overseaEducation")));

			Executives record = new Executives();
			record.setName(name);
			record.setIdCard(idCard);
			record.setMobilephone(mobilephone);

			record.setQq(qq);
			record.setEmail(email);
			record.setResidence(residence);
			record.setAddress(address);
			record.setReason(reason);
			record.setOpinion(opinion);
			record.setDesiredIndustry(desiredIndustry);
			record.setEducation(education);
			record.setGraduateSchool(graduateSchool);
			record.setSubject(subject);
			record.setEducationScheme(educationScheme);
			record.setOverseaEducation(overseaEducation);

			executivesService.save(record);

			map.put("flag", true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * @param request
	 * @param modelMap
	 * @return
	 */
	@ResponseBody
	@RequestMapping("edit.do")
	public Map editNewExecutives(HttpServletRequest request,ModelMap modelMap) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			//自荐人姓名
			String name = String.valueOf(request.getParameter("name"));
			//身份证号
			String idCard = String.valueOf(request.getParameter("idCard"));
			//手机号码
			String mobilephone = String.valueOf(request.getParameter("mobilephone"));
			//QQ
			String qq = String.valueOf(request.getParameter("qq"));
			//电子邮箱地址
			String email = String.valueOf(request.getParameter("email"));
			//户籍所在地址
			int residence = Integer.parseInt(String.valueOf(request.getParameter("residence")));
			//通讯地址
			int address = Integer.parseInt(String.valueOf(request.getParameter("address")));
			//自荐理由
			String reason = String.valueOf(request.getParameter("reason"));
			//创业看法
			String opinion = String.valueOf(request.getParameter("opinion"));
			//关注行业
			int desiredIndustry = Integer.parseInt(String.valueOf(request.getParameter("desiredIndustry")));
			//最终学历
			int education = Integer.parseInt(String.valueOf(request.getParameter("education")));
			//毕业学校
			String graduateSchool = String.valueOf(request.getParameter("graduateSchool"));
			//专业
			String subject = String.valueOf(request.getParameter("subject"));
			//教育模式
			int educationScheme = Integer.parseInt(String.valueOf(request.getParameter("educationScheme")));
			//海外教育经验
			int overseaEducation = Integer.parseInt(String.valueOf(request.getParameter("oversea_education")));

			Executives record = new Executives();
			record.setName(name);
			record.setIdCard(idCard);
			record.setMobilephone(mobilephone);

			record.setQq(qq);
			record.setEmail(email);
			record.setResidence(residence);
			record.setAddress(address);
			record.setReason(reason);
			record.setOpinion(opinion);
			record.setDesiredIndustry(desiredIndustry);
			record.setEducation(education);
			record.setGraduateSchool(graduateSchool);
			record.setSubject(subject);
			record.setEducationScheme(educationScheme);
			record.setOverseaEducation(overseaEducation);

			executivesService.save(record);

			map.put("flag", true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	/**投递历史查询
	 * @param request
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("historyList/{userId}.do")
	public String queryHistoryList(HttpServletRequest request,ModelMap modelMap, @PathVariable("userId") Long userId) {
		List<Project> varProjectList = projectService.queryProjectDelievery(request, modelMap, userId);
		List<Recruit> varRecruitList = recruitDeliverService.queryRecruitDelievery(request, modelMap, userId);

		if(modelMap != null){
			modelMap.addAttribute("varProjectList", varProjectList);
			modelMap.addAttribute("varRecruitList", varRecruitList);
		}
		return JSP_PATH+"executives-history";
	}

}
